package com.mes.defece.controller;

import com.mes.defece.service.TestingProjectService;
import com.mes.pojo.defece.TestingProject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Author 侯伟豪
 * @Company 起点编程
 * @Description
 * @Time 2024/10/17 16:56
 */
@RestController
@CrossOrigin
@RequestMapping("/testingProject")
public class TestingProjectController {
    @Autowired
    private TestingProjectService testingProjectService;
//    导出数据
@GetMapping("/export")
public Object export(TestingProject testingProject, @RequestParam(defaultValue = "1")int page, @RequestParam(defaultValue = "10")int limit, HttpServletResponse response) throws IOException {
    return testingProjectService.getExport(testingProject, page, limit);
}
//    分页查询所有数据
    @GetMapping("/selectAll")
    public Object selectAll(TestingProject testingProject, @RequestParam(defaultValue = "1" ) Integer page,@RequestParam(defaultValue = "10") Integer limit,HttpServletResponse response) throws IOException {
        return testingProjectService.selectAll(testingProject, page, limit);
    }
//    新增数据
    @PostMapping("/add")
    public Object add(@RequestBody TestingProject testingProject) {
        System.out.println("+++=====>>>"+testingProject);
        return testingProjectService.addTestingProject(testingProject);
    }
//    根据id查询数据信息
    @GetMapping("/selectById")
    public Object selectById(Long testingProjectId) {
        return testingProjectService.selectById(testingProjectId);
    }
//    根据id修改数据信息
    @PostMapping("/update")
    public Object update(@RequestBody TestingProject testingProject) {
        return testingProjectService.updateTestingProject(testingProject);
    }
//    根据id删除数据信息
    @DeleteMapping("/delete")
    public Object delete(Long testingProjectId) {
        return testingProjectService.deleteTestingProject(testingProjectId,99);
    }
//    根据检测模版id查询检测项目信息
    @GetMapping("/selectByTemplateId")
    public Object selectByTemplateId(Integer TestingProjectTemplateId) {
        return testingProjectService.selectByTemplateId(TestingProjectTemplateId);
    }
}